package com.coder520.sync_learning.demo;

import java.util.Iterator;
import java.util.concurrent.TimeUnit;

public class Join {
	
	public static void main(String[] args) throws InterruptedException {
		Thread thread=Thread.currentThread();
		
		
		for (int i = 0; i < 10; i++) {
//			每个线程拥有当前一个线程的引用，需要等待当前一个线程终止，才能从等待中返回
			Thread threads=new Thread(new Domino(thread),String.valueOf(i));
			
			threads.start();
			
			thread=threads;
		}
		
		TimeUnit.SECONDS.sleep(10);
		
		System.out.println(Thread.currentThread().getName()+"  terminae.");
	}
 static class Domino implements Runnable{
	 private Thread thread;
	 public Domino(Thread thread) {
		// TODO Auto-generated constructor stub
		 this.thread=thread;
		 
	}
	 @Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			thread.join();
		} catch (Exception e) {
			// TODO: handle exception
		}
		System.out.println(Thread.currentThread().getName()+"terminate.");
	}
	 
	 
 }
}
